package com.ruoyi.web.controller.squad;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.squadweb.domain.SquadjsMapInfo;
import com.ruoyi.squadweb.service.ISquadjsMapInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 地图信息Controller
 *
 * @author LJY
 * @date 2023-10-22
 */
@RestController
@RequestMapping("/squad/Mapinfo")
public class SquadjsMapInfoController extends BaseController
{
    @Autowired
    private ISquadjsMapInfoService squadjsMapInfoService;

    /**
     * 查询地图信息列表
     */
    @PreAuthorize("@ss.hasPermi('squad:Mapinfo:query')")
    @GetMapping("/list")
    public TableDataInfo list(SquadjsMapInfo squadjsMapInfo)
    {
        startPage();
        List<SquadjsMapInfo> list = squadjsMapInfoService.selectSquadjsMapInfoList(squadjsMapInfo);
        return getDataTable(list);
    }

    /**
     * 导出地图信息列表
     */
    @PreAuthorize("@ss.hasPermi('squad:Mapinfo:export')")
    @Log(title = "地图信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SquadjsMapInfo squadjsMapInfo)
    {
        List<SquadjsMapInfo> list = squadjsMapInfoService.selectSquadjsMapInfoList(squadjsMapInfo);
        ExcelUtil<SquadjsMapInfo> util = new ExcelUtil<SquadjsMapInfo>(SquadjsMapInfo.class);
        util.exportExcel(response, list, "地图信息数据");
    }

    /**
     * 获取地图信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('squad:Mapinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(squadjsMapInfoService.selectSquadjsMapInfoById(id));
    }

    /**
     * 新增地图信息
     */
    @PreAuthorize("@ss.hasPermi('squad:Mapinfo:add')")
    @Log(title = "地图信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SquadjsMapInfo squadjsMapInfo)
    {
        return toAjax(squadjsMapInfoService.insertSquadjsMapInfo(squadjsMapInfo));
    }

    /**
     * 修改地图信息
     */
    @PreAuthorize("@ss.hasPermi('squad:Mapinfo:edit')")
    @Log(title = "地图信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SquadjsMapInfo squadjsMapInfo)
    {
        return toAjax(squadjsMapInfoService.updateSquadjsMapInfo(squadjsMapInfo));
    }

    /**
     * 删除地图信息
     */
    @PreAuthorize("@ss.hasPermi('squad:Mapinfo:remove')")
    @Log(title = "地图信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(squadjsMapInfoService.deleteSquadjsMapInfoByIds(ids));
    }
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<SquadjsMapInfo> util = new ExcelUtil<SquadjsMapInfo>(SquadjsMapInfo.class);
        util.importTemplateExcel(response, "地图信息");
    }
    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('squad:mapInfo:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<SquadjsMapInfo> util = new ExcelUtil<SquadjsMapInfo>(SquadjsMapInfo.class);
        List<SquadjsMapInfo> userList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = squadjsMapInfoService.importMapInfo(userList, updateSupport, operName);
        return success(message);
    }
}
